<template>
  <div class="adminSet">
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="200px" class="demo-ruleForm">
      <el-tabs v-model="attrType" type="card" @tab-click="tabChange" :before-leave="tabBeforeLeave">
        <el-row>
          <el-col :span="24" style="text-align: center; margin-top: 0px">
            <el-button class="float-button" type="primary" size="mini" round @click="resetForm()">返回
            </el-button>
          </el-col>
        </el-row>
        <el-tab-pane label="基本信息" name="first">
          <el-form-item label prop></el-form-item>
          <el-form-item label="商品类型" prop="goodsStyle">
            <el-select v-model="ruleForm.goodsStyle" class="input_edit" placeholder="请选择" clearable>
              <el-option label="普通商品" :value="1"></el-option>
              <el-option label="宴席商品" :value="2"></el-option>
              <el-option label="生日专属商品" :value="3"></el-option>
              <el-option label="预售商品" :value="4"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="是否订单唯一" prop="isOnly" v-if="ruleForm.goodsStyle == '2'">
            <el-radio v-model="ruleForm.isOnly" label="1">是</el-radio>
            <el-radio v-model="ruleForm.isOnly" label="0">否</el-radio>
          </el-form-item>
          <el-form-item label="商品名称" prop="goodsName">
            <el-input v-model="ruleForm.goodsName" class="input_edit" @change="handlerPageNo"></el-input>
          </el-form-item>

          <el-form-item label="惊喜价" prop="activityPrice" v-if="ruleForm.goodsStyle == '3'">
            <el-input v-model="ruleForm.activityPrice" :maxlength="10" oninput="value=value.replace(/[^0-9.]/g,'')"
              class="input_edit" style="text-align-last: right" placeholder="惊喜价" @change="
                (data) => {
                  ruleForm.activityPrice = toPrice2(data);
                }
              ">
              <template slot="append">元</template>
            </el-input>
          </el-form-item>

          <el-form-item label="惊喜价有效期" prop="dateRange" v-if="ruleForm.goodsStyle == '3'" :rules="[
            {
              type: 'array',
              required: true,
              message: '请选择惊喜价有效期',
              trigger: 'change',
            },
          ]">
            <el-date-picker v-model="ruleForm.dateRange" type="datetimerange" range-separator="至"
              start-placeholder="开始时间" end-placeholder="结束时间" value-format="yyyy-MM-dd HH:mm:ss"
              :picker-options="pickerOptions" :default-time="['00:00:00', '23:59:59']"></el-date-picker>
          </el-form-item>

          <el-form-item label="国际条码" prop="barCode">
            <el-input v-model="ruleForm.barCode" class="input_edit" :maxlength="30" :disabled="!this.editflag">
            </el-input>
          </el-form-item>
          <el-form-item v-if="ruleForm.goodsStyle == 1 || ruleForm.goodsStyle == 4" label="首页推荐" prop="recommend">
            <el-radio-group v-model="ruleForm.recommend">
              <el-radio :label="0">不推荐</el-radio>
              <el-radio :label="1">推荐</el-radio>
            </el-radio-group>
          </el-form-item>
          <!-- <div class="form-item-inline"></div> -->

          <el-form-item label="建议零售价" prop="salePrice">
            <el-input v-model="ruleForm.salePrice" :maxlength="10" oninput="value=value.replace(/[^0-9.]/g,'')"
              class="input_edit" style="text-align-last: right" placeholder="零售价" @change="
                (data) => {
                  ruleForm.salePrice = toPrice2(data);
                }
              ">
              <template slot="append">元</template>
            </el-input>
            <p class="tips">
              *划线价，商品正常售卖指导价
            </p>
          </el-form-item>
          <el-form-item v-if="ruleForm.goodsStyle == 1 || ruleForm.goodsStyle == 4" label="商品限价" prop="saleLowerPrice">
            <el-input v-model="ruleForm.saleLowerPrice" :maxlength="10" oninput="value=value.replace(/[^0-9.]/g,'')"
              class="input_edit" style="text-align-last: right" placeholder="限价" @change="
                (data) => {
                  ruleForm.saleLowerPrice = toPrice2(data);
                }
              ">
              <template slot="append">元</template>
            </el-input>
          </el-form-item>

          <el-form-item label="会员价" prop="memberPrice" v-if="ruleForm.goodsStyle == 1 || ruleForm.goodsStyle == 4">
            <el-input v-model="ruleForm.memberPrice" :maxlength="10" oninput="value=value.replace(/[^0-9.]/g,'')"
              class="input_edit" style="text-align-last: right" placeholder="会员价" @change="
                (data) => {
                  ruleForm.memberPrice = toPrice2(data);
                }
              ">
              <template slot="append">元</template>
            </el-input>
            <p class="tips">
              *实际售卖价
            </p>
          </el-form-item>
          <!-- <div class="form-item-inline"></div> -->

          <el-form-item label="商品分类" prop="goodsTypeId">
            <el-select v-model="ruleForm.goodsTypeId" class="input_edit" @change="getProductType(ruleForm.goodsTypeId)">
              <el-option v-for="(send, i) in typeData" :key="i" :value="send.goodsTypeId" :label="send.goodsTypeName">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="消费者酒币" prop="consumerIntegral" v-if="ruleForm.goodsStyle == 1 || ruleForm.goodsStyle == 4">
            <el-input v-model="ruleForm.consumerIntegral" class="input_edit" :maxlength="30">
            </el-input>
          </el-form-item>

          <el-form-item label="商家云币" prop="merchantIntegral" v-if="ruleForm.goodsStyle == 1 || ruleForm.goodsStyle == 4">
            <el-input v-model="ruleForm.merchantIntegral" class="input_edit" :maxlength="30">
            </el-input>
          </el-form-item>
          <!-- <div class="form-item-inline"></div> -->

          <el-form-item label="商品单位" prop="unit">
            <el-select v-model="ruleForm.unit" class="input_edit">
              <el-option v-for="(send, i) in unitData" :key="i" :value="send.uuid" :label="send.unitName">
              </el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="商品标签" prop="labellist" v-if="ruleForm.goodsStyle == 1 || ruleForm.goodsStyle == 4">
            <el-input v-model="ruleForm.labellist" type="textarea" placeholder="请输入商品标签，用英文逗号隔开多个标签"
              style="width: 600px;" :autosize="{ minRows: 4 }"></el-input>
          </el-form-item>

          <el-form-item label="展示顺序" prop="sortNo">
            <el-input v-model="ruleForm.sortNo" :maxlength="4" class="input_edit" style="text-align-last: right"
              :min="1"></el-input>
          </el-form-item>
          <el-form-item label="最小购买数" class="item" prop="minBuyCount" v-if="ruleForm.goodsStyle == 2">
            <el-input v-model.number="ruleForm.minBuyCount" :maxlength="4" :min="1" type="number"
              oninput="value=value.replace(/[^0-9]/g,'')" class="input_edit" style="text-align-last: right"
              placeholder="最小购买数" v-on:blur="check(ruleForm.minBuyCount)">
              <template v-if="ruleForm.unit == 'u01p-50'" slot="append">箱</template>
              <template v-if="ruleForm.unit == 'u01p-06'" slot="append">瓶</template>
              <template v-if="ruleForm.unit == 'u01p-07'" slot="append">套</template>
            </el-input>
          </el-form-item>
          <!-- <el-form-item label="标签类型" prop="tagType">
            <div style="margin-top: 0px">
              <el-checkbox-group v-model="ruleForm.tagType" @change="test">
                <el-checkbox-button v-for="item in tagTypeform.tagTypeCodes" :key="item.id" :label="item.id">
                  {{ item.label }}
                </el-checkbox-button>
              </el-checkbox-group>
            </div>
          </el-form-item> -->
          <!-- <el-form-item label="是否最小单位" prop="isMinUnit">
            <el-radio v-model="ruleForm.isMinUnit" label="1">是</el-radio>
            <el-radio v-model="ruleForm.isMinUnit" label="0">否</el-radio>
          </el-form-item> -->

          <el-form-item label="最小单位商品" prop="minUnitGoodsId" v-if="ruleForm.isMinUnit != '1'">
            <el-select class="input_edit" filterable v-model="ruleForm.minUnitGoodsId" clearable :rules="[
              {
                required: true,
                message: '最小单位商品不能为空',
                trigger: 'blur',
              },
            ]">
              <el-option v-for="send in minUnitGoodsIdData" :key="send.goodsId" :value="send.goodsId"
                :label="send.goodsName + '(单位：' + send.unitName + ')'"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="单位转换比例" prop="unitConvertRate" v-if="ruleForm.isMinUnit != '1'">
            <el-input v-model="ruleForm.unitConvertRate" class="input_edit" :rules="[
              {
                required: true,
                message: '单位转换比例不能为空',
                trigger: 'blur',
              },
            ]" onkeypress="return (/[\d]/.test(String.fromCharCode(event.keyCode)))" placeholder="请输入正整数"></el-input>
          </el-form-item>

          <el-form-item label="是否为限购商品" prop="isBuyLimit">
            <el-radio v-model="ruleForm.goodsLimitConfig.isBuyLimit" label="1"
              :disabled="isBuyLimitdisabled || !this.editflag">是</el-radio>
            <el-radio v-model="ruleForm.goodsLimitConfig.isBuyLimit" label="0"
              :disabled="isBuyLimitdisabled || !this.editflag">否</el-radio>
          </el-form-item>
          <div v-if="ruleForm.goodsLimitConfig.isBuyLimit != 0">
            <!-- <el-row :span="12">
                            <el-col :span="10">
                                <el-form-item label="商品时效性" prop="dateRange">
                                    <el-date-picker
                                        v-model="dateRange"
                                        type="datetimerange"
                                        range-separator="至"
                                        start-placeholder="开始时间"
                                        end-placeholder="结束时间"
                                        value-format="yyyy-MM-dd HH:mm:ss"
                                        :picker-options="pickerOptions"
                                    ></el-date-picker>
                                </el-form-item>
                            </el-col>
                            <el-col :span="2">
                                <el-form-item>
                                    <el-checkbox v-model="checked1" style="border-radius: 50%;">不限时间</el-checkbox>
                                </el-form-item>
                            </el-col>
                        </el-row>-->
            <el-row :span="12">
              <el-col :span="10">
                <el-form-item v-if="ruleForm.unit == 'u01p-06'" label="每个用户只能购买(瓶)" prop="limitCount">
                  <el-input v-model="ruleForm.goodsLimitConfig.limitCount" type="number" :min="ruleForm.minBuyCount"
                    class="input_edit" style="text-align-last: right"
                    onkeypress="return (/[\d]/.test(String.fromCharCode(event.keyCode)))" placeholder="请输入正整数" clearable
                    :disabled="checked2" @onchange="
                      dayCountCheck(ruleForm.goodsLimitConfig.limitCount)
                      "></el-input>
                  <p class="tips">
                    *单个用户只能购买此商品设定限制瓶数
                  </p>
                </el-form-item>
                <el-form-item v-if="ruleForm.unit == 'u01p-50'" label="每个用户只能购买(箱)" prop="limitCount">
                  <el-input v-model="ruleForm.goodsLimitConfig.limitCount" type="number" :min="ruleForm.minBuyCount"
                    class="input_edit" style="text-align-last: right"
                    onkeypress="return (/[\d]/.test(String.fromCharCode(event.keyCode)))" placeholder="请输入正整数" clearable
                    :disabled="checked2" @onchange="
                      dayCountCheck(ruleForm.goodsLimitConfig.limitCount)
                      "></el-input>
                  <p class="tips">
                    *单个用户只能购买此商品设定限制箱数
                  </p>
                </el-form-item>
                <el-form-item v-if="ruleForm.unit == 'u01p-07'" label="每个用户只能购买(套)" prop="limitCount">
                  <el-input v-model="ruleForm.goodsLimitConfig.limitCount" type="number" :min="ruleForm.minBuyCount"
                    class="input_edit" style="text-align-last: right"
                    onkeypress="return (/[\d]/.test(String.fromCharCode(event.keyCode)))" placeholder="请输入正整数" clearable
                    :disabled="checked2" @onchange="
                      dayCountCheck(ruleForm.goodsLimitConfig.limitCount)
                      "></el-input>
                  <p class="tips">
                    *单个用户只能购买此商品设定限制套数
                  </p>
                </el-form-item>
              </el-col>
              <el-col :span="2">
                <el-form-item label prop="isSingleBuyLimit">
                  <el-checkbox v-model="checked2" style="border-radius: 50%" :disabled="ruleForm.goodsLimitConfig.limitCount.length > 0 &&
                    !checked2
                    ">不限量</el-checkbox>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :span="12">
              <el-col :span="10">
                <el-form-item label="大区上架数量限制" prop="shelfLimitCount">
                  <el-input v-model="ruleForm.goodsLimitConfig.shelfLimitCount" type="number" :min="1"
                    class="input_edit" style="text-align-last: right"
                    onkeypress="return (/[\d]/.test(String.fromCharCode(event.keyCode)))" placeholder="请输入正整数" clearable
                    :disabled="checked3"></el-input>
                  <p class="tips">
                    *设置上架数量后，商家端不能修改库存量
                  </p>
                </el-form-item>
              </el-col>
              <el-col :span="2">
                <el-form-item label prop="isWarzoneShelfLimit">
                  <el-checkbox v-model="checked3" style="border-radius: 50%" :disabled="ruleForm.goodsLimitConfig.shelfLimitCount.length > 0 &&
                    !checked3
                    ">不限量</el-checkbox>
                </el-form-item>
              </el-col>
            </el-row>
          </div>
        </el-tab-pane>

        <el-tab-pane label="详细信息" name="second">
          <el-form-item label prop>
            <span style="
                                margin-left: 0%;
                                margin-top: 22%;
                                margin-bottom: 20px;
                                font-size: 20px;
                                color: #000000;
                            "></span>
          </el-form-item>
          <el-form-item label="商品主图" prop required>
            <el-row>
              <el-col style="margin: 10px; 0px; 10px; 0">
                <el-upload style="margin: 10px" :action="action" :limit="1" list-type="picture-card"
                  :on-preview="handlePreview" :on-remove="handleRemove6" :file-list="fileList6" :on-success="upLoadPic6"
                  :headers="headers" :on-exceed="handleExceed">
                  <i class="el-icon-plus"></i>
                </el-upload>
                <p class="tips">
                  注：上传图片（限1M），尺寸为750*750，图片将用于消费者端产品详情图页
                </p>
              </el-col>
            </el-row>
          </el-form-item>
          <el-form-item label="详情图片" prop required>
            <el-row>
              <el-col style="margin: 10px; 0px; 10px; 0">
                <el-upload style="margin: 10px" :action="action" :limit="1" list-type="picture-card"
                  :on-preview="handlePreview" :on-remove="handleRemove3" :file-list="fileList3" :on-success="upLoadPic3"
                  :headers="headers" :on-exceed="handleExceed">
                  <i class="el-icon-plus"></i>
                </el-upload>
                <p class="tips">
                  注：上传图片（限2M），尺寸为750*长度不限，图片将用于消费者端产品详情图页
                </p>
              </el-col>
            </el-row>
          </el-form-item>
          <el-form-item label="商品展示图" prop required>
            <el-row>
              <el-col style="margin: 10px; 0px; 10px; 0">
                <draggable class="list-group" tag="ul" v-model="fileList2" v-bind="dragOptions" @start="drag = true"
                  @end="drag = false">
                  <!--<transition-group type="transition" :name="!drag ? 'flip-list' : null">-->
                  <div v-loading="loadingapp" class="img-wrapper divBox" v-for="(item, index) in fileList2">
                    <img :src="item.url" v-if="item.url" width="148" height="148" class="imgSty"
                      @click="handlePreview(item)" />
                    <i class="el-icon-delete delIcon" @click="deleImg(item.URL, index)"></i>
                    <!--<img class="img-big" :src="imgUrl" v-else width="362" height="272">-->
                  </div>
                  <!--</transition-group>-->
                </draggable>
                <el-upload style="margin: 10px" :action="action" :on-preview="handlePreview" :on-success="upLoadPic"
                  list-type="picture-card" :headers="headers" :show-file-list="false">
                  <i class="el-icon-plus"></i>
                </el-upload>
              </el-col>
            </el-row>
            <p class="tips">
              注：上传图片（限1M），尺寸为750*750，图片将用于消费者端产品详情图页
            </p>
          </el-form-item>
        </el-tab-pane>
        <el-tab-pane label="扩展信息" name="third">
          <el-form-item label prop></el-form-item>
          <el-form-item label prop></el-form-item>
          <vue-ueditor-wrap v-model="ruleForm.goodsDescribe" :config="myConfig" @ready="ready" :destroy="true">
          </vue-ueditor-wrap>
        </el-tab-pane>
        <!-- <el-tab-pane label="扩展信息" name="fourth">
                </el-tab-pane>-->

        <el-row>
          <el-col :span="24" style="text-align: center; margin-top: 30px">
            <el-button @click="resetForm()" size="mini">取消</el-button>
            <el-button type="primary" size="mini" icon="arrow-left" @click="prev" v-if="active != 1">上一步
            </el-button>
            <el-button type="primary" size="mini" icon="arrow-right" @click="next" v-if="active != 3">下一步
            </el-button>
            <el-button type="primary" size="mini" @click="submitForm('ruleForm')" v-if="active == 3"
              :disabled="isDisable" :loading="loading">提交</el-button>
          </el-col>
        </el-row>
        <el-dialog :visible.sync="dialogVisibleImg" size="tiny">
          <img width="100%" :src="dialogImageUrl" alt />
        </el-dialog>
      </el-tabs>
    </el-form>
  </div>
</template>
<script>
import draggable from 'vuedraggable';
import VueUeditorWrap from 'vue-ueditor-wrap';
import {
  getInfoMax,
  checkCode,
  queryStockGoods,
  queryGoodsCategorys,
  getProductUnitList,
  getGoodsInfoList,
  delGoodsPicture,
  queryGoodsBrands,
  createGoodsInfo,
  modifyGoodsInfo,
  deleteGoodsInfo,
  queryGoodsInfoAll,
  addGoodsGroup,
  getGoodsGroupList,
  batchaRenewGoodsParam,
  getGoodsParamsList,
} from '@/api/compositegoods';
import { querycodeByName } from '@/api/dictionary';
import { queryGoodsTypeList } from '@/api/tagmanage';
import qs from 'qs';

const isMoney = function (rule, value, callback) {
  const reg = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/;
  if (!value) {
    return callback(new Error('金额不能为空'));
  } else if (!reg.test(value)) {
    return callback(new Error('金额格式错误'));
  } else {
    callback();
  }
};
const checkCodeFunction1 = function (rule, value, callback) {
  if (!value) {
    return callback(new Error('条码不能为空'));
  }
  let data = {
    barCode: value,
  };
  checkCode(data).then((res) => {
    if (res.code == 0) {
      callback(new Error(value + '已存在'));
    } else {
      callback();
    }
  });
};
const checkCodeFunction2 = function (rule, value, callback) {
  if (!value) {
    return callback(new Error('条码不能为空'));
  }
  let data = {
    sysCode: value,
  };
  checkCode(data).then((res) => {
    if (res.code == 0) {
      if (res.code == 0) {
        callback(new Error(value + '已存在'));
      } else {
        callback();
      }
    }
  });
};

export default {
  components: {
    draggable,
    VueUeditorWrap,
  },
  data() {
    return {
      loadingapp: false,
      drag: false,
      keepAlive: true,
      checked1: false,
      checked2: false,
      checked3: false,
      action: `${process.env.VUE_APP_BASE_API}/api/file-service/v1/file/uploadFile`,
      listQuery: {
        current: 1,
        size: 10,
      },
      formInline: {
        goodsName: '',
      },
      headers: {
        token: localStorage.getItem('token'), //从cookie里获取token，并赋值  Authorization ，而不是token
      },
      attrType: 'first',
      active: 1,
      editflag: false,
      isDisable: false,
      dialogVisibleFeatures: false,
      dialogVisibleFeaturesParam: false,
      dialogVisible: false,
      isBuyLimitdisabled: false,
      tableData: [],
      total: 0,
      strData: [],
      typeData: [],
      groupData: [
        {
          groupId: '1f7b7435-5488-431d-930c-c9eb076de417',
          groupName: '五粮液产品参数',
        },
      ],
      brandData: [],
      minUnitGoodsIdData: [],
      unitData: [],
      supplyData: [],
      selectData: [],
      featuresForm: {
        groupId: '',
        groupName: '',
      },
      featuresParamForm: {
        groupId: '',
        parameterName: '',
        sortNo: '0',
        parameterId: '',
        valueId: '',
      },
      featuresParamList: [
        {
          groupId: '',
          parameterName: '',
          sortNo: '0',
          parameterId: '',
          valueId: '',
        },
      ],
      featuresParamData: [],
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() < Date.now() - 24 * 60 * 60 * 1000;
        },
        shortcuts: [
          {
            text: '最近一周',
            onClick(picker) {
              const end = new Date();
              const start = new Date(
                new Date(new Date().toLocaleDateString()).getTime() +
                24 * 60 * 60 * 1000
              );
              end.setTime(start.getTime() + 3600 * 1000 * 24 * 7 - 1);
              picker.$emit('pick', [start, end]);
            },
          },
          {
            text: '最近一个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date(
                new Date(new Date().toLocaleDateString()).getTime() +
                24 * 60 * 60 * 1000
              );
              end.setTime(start.getTime() + 3600 * 1000 * 24 * 30 - 1);
              picker.$emit('pick', [start, end]);
            },
          },
          {
            text: '最近三个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date(
                new Date(new Date().toLocaleDateString()).getTime() +
                24 * 60 * 60 * 1000
              );
              end.setTime(start.getTime() + 3600 * 1000 * 24 * 90 - 1);
              picker.$emit('pick', [start, end]);
            },
          },
        ],
      },
      dateRange: [],
      loading: false,
      ruleForm: {
        dateRange: [],
        goodsId: '',
        goodsAmount: '',
        goodsStyle: 1,
        isOnly: '1',
        minBuyCount: 1,
        goodsName: '',
        barCode: '',
        sysCode: '',
        goodsTypeId: '',
        unit: '',
        buyPrice: '',
        priceId: '',
        saleLowerPrice: '',
        activityPrice: '',
        salePrice: '',
        saleUpperPrice: '',
        retailPrice: '',
        brandReq: '',
        minUnitGoodsId: '',
        status: '1',
        tagType: [],
        isGift: '0',
        upLower: '1',
        sortNo: '',
        unit: '',
        isMinUnit: '1',
        minUniT: '',
        unitConvertRate: '',
        goodsDescribe: '',
        picture: '',
        pictures: '',
        img: '',
        groupList: [],
        paramValueList: [],
        parameters: [],
        groupId: '1f7b7435-5488-431d-930c-c9eb076de417', //"",
        groupName: '',
        limitCountOld: '',
        goodsLimitConfig: {
          isBuyLimit: '0', //是否限购商品(1-是0-否)
          isTimeLimit: '0', //是否时效性商品(1-是0-否)
          limitCreateTime: '', //开始时间
          limitEndTime: '', //结束时间
          isSingleBuyLimit: '1', //每个用户购买是否限量(1-是0-否)
          limitCount: '', //用户购买限制数
          isWarzoneShelfLimit: '1', //大区上架数量是否限量(1-是0-否)
          shelfLimitCount: '', //大区上架限制数
        },
        recommend: '',
        memberPrice: '',
        consumerIntegral: 0,
        merchantIntegral: 0,
        labellist: ''
      },
      dialogVisibleImg: false,
      dialogImageUrl: '',
      fileList2: [],
      fileList6: [],
      fileList3: [],
      tagTypeform: {
        tagTypeCodes: [],
      },
      total: '',
      myConfig: {
        // 编辑器不自动被内容撑高
        autoHeightEnabled: false,
        // 初始容器高度
        initialFrameHeight: 240,
        // 初始容器宽度
        initialFrameWidth: '100%',
        // 上传文件接口（这个地址是我为了方便各位体验文件上传功能搭建的临时接口，请勿在生产环境使用！！！）
        //   serverUrl: 'http://35.201.165.105:8000/controller.php',
        serverUrl: `${process.env.VUE_APP_BASE_API}/api/file-service/v1/file/uploadFile`,
        // UEditor 资源文件的存放路径，如果你使用的是 vue-cli 生成的项目，通常不需要设置该选项，vue-ueditor-wrap 会自动处理常见的情况，如果需要特殊配置，参考下方的常见问题2
        UEDITOR_HOME_URL:
          process.env.NODE_ENV == 'production'
            ? '../../ui/static/UEditor/'
            : '../../static/UEditor/',
        // UEDITOR_HOME_URL: "../../static/UEditor/"
      },
      rules: {
        goodsName: [
          {
            required: true,
            message: '请输入商品名称',
            trigger: 'blur',
          },
        ],
        goodsStyle: [
          {
            required: true,
            message: '请选择商品类型',
            trigger: 'blur',
          },
        ],
        // sysCode: [
        //   {
        //     required: true,
        //     message: "请输入外部系统码",
        //     trigger: "blur"
        //   },
        //   { validator: checkCodeFunction2, trigger: "blur" }
        // ],
        goodsTypeId: [
          {
            required: true,
            message: '请选择分类',
            trigger: 'blur',
          },
        ],
        unit: [
          {
            required: true,
            message: '请选择单位',
            trigger: 'blur',
          },
        ],
        isMinUnit: [
          {
            required: true,
            message: '请选择最小单位',
            trigger: 'blur',
          },
        ],
        // tagType: [
        //   {
        //     required: true,
        //     message: '请选择标签',
        //     trigger: 'blur',
        //   },
        // ],
        activityPrice: [
          {
            required: true,
            message: '请输入活动价',
            trigger: 'blur',
          },
          {
            validator: isMoney,
            trigger: 'blur',
          },
        ],
        salePrice: [
          {
            required: true,
            message: '请输入标准价',
            trigger: 'blur',
          },
          {
            validator: isMoney,
            trigger: 'blur',
          },
        ],
        saleLowerPrice: [
          {
            required: true,
            message: '请输入商品限价',
            trigger: 'blur',
          },
          {
            validator: isMoney,
            trigger: 'blur',
          },
        ],
        memberPrice: [
          {
            required: true,
            message: '请输入商品会员价',
            trigger: 'blur',
          },
          {
            validator: isMoney,
            trigger: 'blur',
          },
        ],
        saleUpperPrice: [
          {
            required: true,
            message: '请输入上限价',
            trigger: 'blur',
          },
          {
            validator: isMoney,
            trigger: 'blur',
          },
        ],
        consumerIntegral: [
          {
            required: true,
            message: '请输入消费者酒币',
            trigger: 'blur',
          },
        ],
        merchantIntegral: [
          {
            required: true,
            message: '请输入商家云币',
            trigger: 'blur',
          },
        ],
        // upLower: [
        //     {
        //         required: true,
        //         message: "是否强上",
        //         trigger: "blur"
        //     }
        // ]
        // minUnitGoodsId: [
        //     {
        //         required: true,
        //         message: "最小单位商品不能为空",
        //         trigger: "blur"
        //     }
        // ],
        // unitConvertRate: [
        //     {
        //         required: true,
        //         message: "单位转换比例不能为空",
        //         trigger: "blur"
        //     }
        // ]
        // dateRange: [
        //   {
        //     type: 'array',
        //     required: true,
        //     message: "请选择活动价有效期",
        //     trigger: "change"
        //   }
        // ],
      },
    };
  },

  props: {
    value: {
      type: [String, Number],
      default: '',
    },
  },
  computed: {
    goodsId: {
      get() {
        return this.value || '';
      },
      set(value) {
        this.$emit('input', value);
      },
    },
    dragOptions() {
      return {
        animation: 200,
        group: 'description',
        disabled: false,
        ghostClass: 'ghost',
      };
    },
  },

  activated() { },

  mounted() {
    this.logininfo = localStorage.getItem('logininfo');
    this.orgSeq = JSON.parse(this.logininfo).orgSeq;
    this.getProductUnit();
    this.queryGoodsTypeList();
    this.getProductType();
    this.getMinUnitGoodsId();
    // this.getGoodsParamsList();
    // this.total = this.$route.params.total;
    // this.ruleForm.sortNo = this.$route.params.total + 1;
    let v = this.$route.params.edit;
    if (v != undefined) {
      this.editflag = false;
      this.ruleForm.minBuyCount = v.minBuyCount;
      this.isBuyLimitdisabled = v.createTime < '2020-07-01' ? true : false;

      this.ruleForm.priceId = v.priceId;
      this.ruleForm.saleLowerPrice = this.toPrice(v.saleLowerPrice);
      this.ruleForm.activityPrice = this.toPrice(v.activityPrice);
      this.ruleForm.salePrice = this.toPrice(v.salePrice);
      this.ruleForm.memberPrice = this.toPrice(v.memberPrice);
      this.ruleForm.labellist = v.labellist;
      this.ruleForm.recommend = v.recommend;
      this.ruleForm.consumerIntegral = v.consumerIntegral;
      this.ruleForm.merchantIntegral = v.merchantIntegral;
      this.ruleForm.saleUpperPrice = this.toPrice(v.saleUpperPrice);
      this.ruleForm.goodsId = v.goodsId;
      this.ruleForm.barCode = v.barCode;
      this.ruleForm.goodsName = v.goodsName;
      this.ruleForm.goodsStyle = v.goodsStyle;
      this.ruleForm.isOnly = String(v.isOnly);
      this.ruleForm.sortNo = v.sortNo;
      this.ruleForm.minUnitGoodsId = String(
        v.minUnitGoodsId == null ? '' : v.minUnitGoodsId
      );
      this.ruleForm.unitConvertRate = v.unitConvertRate;
      //   this.ruleForm.sysCode = v.sysCode;
      this.ruleForm.goodsTypeId = v.goodsTypeId;
      this.ruleForm.status = String(v.status);
      // this.ruleForm.tagType = v.tagType.split(',');
      this.ruleForm.isGift = String(v.isGift);
      this.ruleForm.upLower = String(v.upLower);
      this.ruleForm.unit = String(v.unit == null ? '' : v.unit);
      this.ruleForm.isMinUnit = String(v.isMinUnit);
      this.ruleForm.minUniT = String(v.minUniT == null ? '' : v.minUniT);
      this.ruleForm.goodsDescribe = v.goodsDescribe;
      this.queryGoodsInfoAll(v);
    } else {
      this.editflag = true;
      this.getInfoMax();
    }
  },
  watch: {
    'ruleForm.minBuyCount': {
      handler(newName, oldName) {
        if (
          this.ruleForm.goodsLimitConfig.isBuyLimit == '1' &&
          !this.checked2
        ) {
          if (this.ruleForm.goodsLimitConfig.limitCount < newName) {
            if (this.ruleForm.goodsLimitConfig.limitCount == '') {
              this.ruleForm.goodsLimitConfig.limitCount = newName;
            }
          }
        }
      },
    },
    'ruleForm.goodsLimitConfig.isBuyLimit': {
      handler(newVal, oldName) {
        if (
          newVal == 1 &&
          this.ruleForm.goodsStyle == 2 &&
          this.ruleForm.goodsLimitConfig.limitCount == ''
        ) {
          this.ruleForm.goodsLimitConfig.limitCount = this.ruleForm.minBuyCount;
        } else {
          this.ruleForm.goodsLimitConfig.limitCount = '';
          this.ruleForm.goodsLimitConfig.shelfLimitCount = '';
        }
      },
      deep: true,
      immediate: true,
    },
  },
  methods: {
    positionTab: function () {
      if (this.active == 1) {
        this.attrType = 'first';
      } else if (this.active == 2) {
        this.attrType = 'second';
        return this.checkvalid();
      } else if (this.active == 3) {
        this.attrType = 'third';
      } else if (this.active == 4) {
        this.attrType = 'fourth';
      }
    },
    next() {
      this.active++;
      this.positionTab();
    },
    prev() {
      this.active--;
      this.positionTab();
    },
    tabChange(val) {
      var name = val.name;
      if (name == 'first') {
        this.active = 1;
      } else if (name == 'second') {
        this.active = 2;
      } else if (name == 'third') {
        this.active = 3;
      } else if (name == 'fourth') {
        this.active = 4;
      }
    },
    tabBeforeLeave() {
      const result = this.checkvalid();
      return !result;
    },

    handlerPageNo() {
      this.userFilter(this.ruleForm.goodsName);
    },
    //过滤最小商品
    userFilter(query = '') {
      this.minUnitGoodsIdData.filter((item) => {
        if (item.goodsName.includes(query) || item.goodsId.includes(query)) {
          this.ruleForm.minUnitGoodsId = item.goodsId;
        }
      });
      // let arr = this.minUnitGoodsIdData.filter((item) => {
      //   return item.goodsName.includes(query) || item.goodsId.includes(query)
      // })
      // if (arr.length > 50) {
      //   this.minUnitGoodsIdData = arr.slice(0, 50)
      // } else {
      //   this.minUnitGoodsIdData = arr
      // }
    },
    getUserWhiteList() {
      let data = {
        size: 100,
        current: 1,
        condition: {
          isMinUnit: '1',
          status: '1',
        },
        ascs: [],
        descs: [],
      };
      getGoodsInfoList(data).then((res) => {
        this.minUnitGoodsIdData = res.records;
        console.log(this.minUnitGoodsIdData, 'pppp');
        this.userFilter();
      });
    },
    addValueOptions() {
      if (this.userId) {
        let target = this.minUnitGoodsIdData.find((item) => {
          // 从大option中找到当前条
          return item.value === this.goodsId;
        });
        if (target) {
          // 将当前条与小option比对，没有则加入
          if (
            this.minUnitGoodsIdData.every((item) => item.value !== target.value)
          ) {
            this.minUnitGoodsIdData.unshift(target);
          }
        }
      }
    },

    //查询商品分类
    getProductType(v) {
      let data = {
        status: '1',
      };
      queryGoodsCategorys(data).then((res) => {
        this.typeData = res.records;
      });
    },
    //查询字典分类
    querycodeByName(v) {
      let data = {
        size: 99,
        current: 1,
        condition: {
          code: '',
          value: '',
          dictId: 'tagType',
        },
      };
      querycodeByName(data).then((res) => {
        this.tagTypeform.tagTypeCodes = [];
        res.records.forEach((item, i) => {
          let data = {
            value: item.code,
            label: item.value,
            selected: i == 0 ? '1' : '0',
          };
          this.tagTypeform.tagTypeCodes.push(data);
        });
      });
    },

    //查询商品单位
    getProductUnit(v) {
      let data = {
        size: 100,
        current: 1,
        condition: {},
        ascs: [],
        descs: [],
      };
      getProductUnitList(data).then((res) => {
        this.unitData = res.records;
      });
    },
    //查询商品品牌
    getProductBrands(v) {
      let data = {
        size: 100,
        current: 1,
        condition: {
          status: '1',
        },
        ascs: [],
        descs: [],
      };
      queryGoodsBrands(data).then((res) => {
        this.brandData = res.records;
      });
    },

    //查询最小单位商品
    getMinUnitGoodsId(v) {
      let data = {
        size: 100,
        current: 1,
        condition: {
          isMinUnit: '1',
          status: '1',
        },
        ascs: [],
        descs: [],
      };
      getGoodsInfoList(data).then((res) => {
        this.minUnitGoodsIdData = res.records;
      });
    },

    //删除图片调用后台
    delGoodsPicture(v) {
      let data = {
        picId: v,
      };
      delGoodsPicture(data).then((res) => { });
    },

    //删除图片
    handleRemove3(file, fileList3) {
      let newfileList = [];
      fileList3.forEach((item, i) => {
        let data = {
          name: item.name,
          url: item.url,
          picId: item.picId,
        };
        newfileList.push(data);
      });
      this.fileList3 = newfileList;
    },
    upLoadPic3(file, fileList3) {
      var picUrl = file.result;
      var name = fileList3.name;
      let data = {
        name: name,
        url: picUrl,
        picType: 3,
      };
      this.fileList3.push(data);
    },

    //删除图片
    handleRemove6(file, fileList6) {
      let newfileList = [];
      fileList6.forEach((item, i) => {
        let data = {
          name: item.name,
          url: item.url,
          picId: item.picId,
        };
        newfileList.push(data);
      });
      this.fileList6 = newfileList;
    },
    upLoadPic6(file, fileList6) {
      var picUrl = file.result;
      var name = fileList6.name;
      let data = {
        name: name,
        url: picUrl,
        picType: 2,
      };
      this.fileList6.push(data);
    },

    //删除图片
    handleRemove(file, fileList) {
      let newfileList = [];
      fileList.forEach((item, i) => {
        let data = {
          name: item.name,
          url: item.url,
          picId: item.picId,
        };
        newfileList.push(data);
      });
      this.fileList2 = newfileList;
    },
    //预览图片
    handlePreview(file) {
      this.dialogImageUrl = file.url;
      this.dialogVisibleImg = true;
    },

    upLoadPic(file, fileList) {
      var picUrl = file.result;
      var name = fileList.name;
      let data = {
        name: name,
        url: picUrl,
        picType: 1,
      };
      this.fileList2.push(data);
    },

    //打开挑选
    selectGoods() {
      this.dialogVisible = true;
      this.queryStockGoods();
    },
    //搜索查询
    search() {
      let data = {
        size: this.listQuery.size,
        current: this.listQuery.current,
        condition: {
          goodsName: this.formInline.goodsName,
          keyWord: this.formInline.goodsName,
          isComb: '0',
          orgSeq: this.orgseq,
        },
        ascs: [],
        descs: [],
      };
      queryStockGoods(data).then((res) => {
        this.tableData = res.records;
        this.total = res.total;
      });
    },
    //初始化查询商品列表
    queryStockGoods() {
      let data = {
        size: this.listQuery.size,
        current: this.listQuery.current,
        condition: {
          goodsName: '',
          keyWord: '',
          isComb: '0',
          orgSeq: this.orgSeq,
        },
        ascs: [],
        descs: [],
      };
      queryStockGoods(data).then((res) => {
        this.tableData = res.records;
        this.total = res.total;
      });
    },
    //初始化查询商品详情
    queryGoodsInfoAll(v) {
      let data = {
        goodsId: v.goodsId,
      };
      queryGoodsInfoAll(data)
        .then((res) => {
          this.ruleForm.paramValueList = res.result.paramValueList;

          if (this.ruleForm.goodsStyle == 1 || this.ruleForm.goodsStyle == 4) {
            this.ruleForm.recommend = res.result.recommend;
            this.ruleForm.memberPrice = res.result.memberPrice;
            this.ruleForm.consumerIntegral = res.result.consumerIntegral;
            this.ruleForm.merchantIntegral = res.result.merchantIntegral;
            this.ruleForm.labellist = res.result.labellist;
          }

          let picture = res.result.picture;
          if (picture !== undefined && picture !== null) {
            var picUrl = picture.picUrl;
            var index = picUrl.lastIndexOf('.');
            var aa = picUrl.substring(index - 5, picUrl.length);
            let data = {
              name: aa,
              picId: picture.picId,
              goodsId: picture.goodsId,
              url: picture.picUrl,
            };
            this.fileList6.push(data);
          }
          let img = res.result.img;
          if (img !== undefined && img != null) {
            var picUrl = img.picUrl;
            var index = picUrl.lastIndexOf('.');
            var aa = picUrl.substring(index - 5, picUrl.length);
            let data = {
              name: aa,
              picId: img.picId,
              goodsId: img.goodsId,
              url: img.picUrl,
            };
            this.fileList3.push(data);
          }

          let pictures = res.result.pictures; //v.pictures;
          if (
            pictures !== undefined &&
            pictures != null &&
            pictures.length > 0
          ) {
            pictures.forEach((item, i) => {
              if (item != null) {
                var picUrl = item.picUrl;
                var index = picUrl.lastIndexOf('.');
                var aa = picUrl.substring(index - 5, picUrl.length);
                var picId = item.picId;
                let data = {
                  name: aa,
                  url: picUrl,
                  picId: picId,
                  picType: 2,
                };
                this.fileList2.push(data);
              }
            });
          }

          let goodsLimitConfig = res.result.goodsLimitConfig;
          if (goodsLimitConfig !== undefined && goodsLimitConfig != null) {
            let beginTime = goodsLimitConfig.limitCreateTime;
            let endTime = goodsLimitConfig.limitEndTime;
            if (beginTime != null && endTime != null) {
              this.ruleForm.dateRange = [beginTime, endTime];
            }
            this.checked1 = goodsLimitConfig.isTimeLimit == '1' ? true : false;
            this.checked2 =
              goodsLimitConfig.isSingleBuyLimit == '1' ? true : false;
            this.checked3 =
              goodsLimitConfig.isWarzoneShelfLimit == '1' ? true : false;
            this.ruleForm.goodsLimitConfig.isBuyLimit = String(
              goodsLimitConfig.isBuyLimit
            );
            this.ruleForm.goodsLimitConfig.shelfLimitCount = String(
              goodsLimitConfig.shelfLimitCount
            );
            this.ruleForm.goodsLimitConfig.limitCount = String(
              goodsLimitConfig.limitCount
            );
            this.ruleForm.limitCountOld = String(goodsLimitConfig.limitCount);
          }
        })
        .then((_) => {
          this.ruleForm.goodsLimitConfig.limitCount = this.ruleForm.limitCountOld;
        });
    },
    //勾选
    handleSelectionChange(list) {
      this.strData = list;
    },
    //保存选择
    save() {
      this.strData.forEach((item, i) => {
        let newGoodId = item.barCode;
        let flag = true;
        this.selectData.forEach((itemOldData, i) => {
          if (newGoodId === itemOldData.goodsId) {
            flag = false;
          }
        });
        if (flag) {
          let data = {
            goodsName: this.strData[i].goodsName,
            goodsId: this.strData[i].barCode,
            goodsAmount: 1,
            barCode: '',
            planItemSeq: '',
          };
          this.selectData.push(data);
        }
      });
      this.dialogVisible = false;
    },

    //移除
    deleteR(v) {
      var goodsId = v.goodsId;
      this.selectData.forEach((item, i) => {
        if (goodsId === this.selectData[i].goodsId) {
          this.selectData.splice(i, 1);
        }
      });
    },
    pruNext() {
      this.active--;
      this.attrType = 'first';
    },
    checkvalid() {
      console.log('this.ruleForm', this.ruleForm.goodsStyle)
      if (this.ruleForm.goodsStyle == '' || this.ruleForm.goodsStyle == null) {
        this.$message.error('请选择商品类型');
        this.pruNext();
        return true;
      }
      if (
        this.ruleForm.goodsStyle == '3' &&
        (this.ruleForm.activityPrice == null ||
          this.ruleForm.activityPrice == '')
      ) {
        this.$message.error('请输入商品活动价');
        this.pruNext();
        return true;
      }
      if (
        this.ruleForm.goodsStyle == '3' &&
        (this.ruleForm.dateRange == null || this.ruleForm.dateRange.length < 1)
      ) {
        this.$message.error('请选择商品惊喜价有效期');
        this.pruNext();
        return true;
      }
      if (this.ruleForm.goodsName == '' || this.ruleForm.goodsName == null) {
        this.$message.error('请输入商品名称');
        this.pruNext();
        return true;
      }
      // 四期新增 start
      if (this.ruleForm.goodsStyle == 1 || this.ruleForm.goodsStyle == 4) {
        if (this.ruleForm.saleLowerPrice == '' || this.ruleForm.saleLowerPrice == null) {
          this.$message.error('请输入商品限价');
          this.pruNext();
          return true;
        }
        if (this.ruleForm.memberPrice == '' || this.ruleForm.memberPrice == null) {
          this.$message.error('请输入商品会员价');
          this.pruNext();
          return true;
        }
        if(parseFloat(this.ruleForm.memberPrice) < parseFloat(this.ruleForm.saleLowerPrice)){
          this.$message.error('商品会员价不能低于商品限价');
          this.pruNext();
          return true;
        }
        if (this.ruleForm.consumerIntegral === '' || this.ruleForm.consumerIntegral == null) {
          this.$message.error('请输入消费者酒币');
          this.pruNext();
          return true;
        }
        if (this.ruleForm.merchantIntegral === '' || this.ruleForm.merchantIntegral == null) {
          this.$message.error('请输入商家云币');
          this.pruNext();
          return true;
        }
      }
      // end

      if (this.ruleForm.salePrice == '' || this.ruleForm.salePrice == null) {
        this.$message.error('请输入建议零售价');
        this.pruNext();
        return true;
      }
      if (
        this.ruleForm.goodsTypeId == '' ||
        this.ruleForm.goodsTypeId == null
      ) {
        this.$message.error('请选择分类');
        this.pruNext();
        return true;
      }
      if (this.ruleForm.unit == '' || this.ruleForm.unit == null) {
        this.$message.error('请选择商品单位');
        this.pruNext();
        return true;
      }
      // if (this.ruleForm.tagType.length == 0) {
      //   this.$message.error('请选择标签');
      //   this.pruNext();
      //   return;
      // }
      if (this.ruleForm.goodsStyle == 2) {
        if (
          this.ruleForm.minBuyCount == '' ||
          this.ruleForm.minBuyCount == null
        ) {
          this.$message.error('宴席商品请输入最小购买数');
          this.pruNext();
          return true;
        }
      }
      if (
        this.ruleForm.dateRange == null ||
        this.ruleForm.dateRange.length == 0
      ) {
        this.ruleForm.goodsLimitConfig.limitCreateTime = null;
        this.ruleForm.goodsLimitConfig.limitEndTime = null;
      } else {
        this.ruleForm.goodsLimitConfig.limitCreateTime = this.ruleForm.dateRange[0];
        this.ruleForm.goodsLimitConfig.limitEndTime = this.ruleForm.dateRange[1];
      }

      this.ruleForm.goodsLimitConfig.isTimeLimit = this.checked1 ? '1' : '0';
      this.ruleForm.goodsLimitConfig.isSingleBuyLimit = this.checked2
        ? '1'
        : '0';
      this.ruleForm.goodsLimitConfig.isWarzoneShelfLimit = this.checked3
        ? '1'
        : '0';
      if (this.checked2 && this.checked3) {
        this.ruleForm.goodsLimitConfig.isBuyLimit = '0';
      }
      if (this.ruleForm.goodsLimitConfig.isBuyLimit == '0') {
        this.ruleForm.goodsLimitConfig.isSingleBuyLimit = 1;
        this.ruleForm.goodsLimitConfig.isWarzoneShelfLimit = 1;
      }
      console.log(this.ruleForm.goodsLimitConfig);

      if (this.ruleForm.goodsLimitConfig.isBuyLimit == '1') {
        if (
          this.ruleForm.goodsLimitConfig.isSingleBuyLimit == '0' &&
          this.ruleForm.goodsLimitConfig.limitCount == ''
        ) {
          this.$message.error('限购时，用户购买数及不限量不能同时为空');
          this.pruNext();
          return true;
        }
        if (
          this.ruleForm.goodsLimitConfig.isWarzoneShelfLimit == '0' &&
          this.ruleForm.goodsLimitConfig.shelfLimitCount == ''
        ) {
          this.$message.error('限购时，大区上架数量限制及不限量不能同时为空');
          this.pruNext();
          return true;
        }
        if (
          this.ruleForm.goodsStyle == 2 &&
          !this.checked2 &&
          this.ruleForm.goodsLimitConfig.limitCount < this.ruleForm.minBuyCount
        ) {
          this.$message.error('限购时，用户购买数不能低于最小购买数');
          this.pruNext();
          return true;
        }
        if (
          this.ruleForm.goodsStyle == 2 &&
          !this.checked3 &&
          this.ruleForm.goodsLimitConfig.shelfLimitCount <
          this.ruleForm.minBuyCount
        ) {
          this.$message.error('限购时，大区上架数量限制不能低于最小购买数');
          this.pruNext();
          return true;
        }
      }
    },
    //保存
    submitForm(formName) {
      // this.$refs[formName].validate(valid => {
      this.checkvalid();
      // if (valid) {
      // alert("submit!");
      // if (this.ruleForm.goodsStyle == "" || this.ruleForm.goodsStyle == null) {
      //   this.$message.error("请选择商品类型");
      //   return;
      // }
      // if (this.ruleForm.goodsName == "" || this.ruleForm.goodsName == null) {
      //   this.$message.error("请输入商品名称");
      //   return;
      // }
      // if (this.ruleForm.salePrice == "" || this.ruleForm.salePrice == null) {
      //   this.$message.error("请输入总部标准价");
      //   return;
      // }
      // if (
      //   this.ruleForm.goodsTypeId == "" ||
      //   this.ruleForm.goodsTypeId == null
      // ) {
      //   this.$message.error("请选择分类");
      //   return;
      // }
      // if (this.ruleForm.unit == "" || this.ruleForm.unit == null) {
      //   this.$message.error("请选择商品单位");
      //   return;
      // }
      // if (this.ruleForm.tagType.length == 0) {
      //   this.$message.error("请选择标签");
      //   return;
      // }
      // if (this.ruleForm.goodsStyle != "" && this.ruleForm.goodsStyle != null) {
      //   if (this.ruleForm.minBuyCount == "" || this.ruleForm.minBuyCount == null) {
      //   this.$message.error("宴席商品请输入最小购买数");
      //   return;
      //   }
      // }
      if (this.fileList6 == undefined || this.fileList6.length <= 0) {
        this.$message.error('请上传商品主图');
        return;
      }
      if (this.fileList2 == undefined || this.fileList2.length <= 0) {
        this.$message.error('请上传展示图片');
        return;
      }
      if (this.fileList3 == undefined || this.fileList3.length <= 0) {
        this.$message.error('请上传商品详情');
        return;
      }
      //       if (this.dateRange == null || this.dateRange.length == 0) {
      //         this.ruleForm.goodsLimitConfig.limitCreateTime = null;
      //         this.ruleForm.goodsLimitConfig.limitEndTime = null;
      //       }else{
      //         this.ruleForm.goodsLimitConfig.limitCreateTime = this.dateRange[0];
      //         this.ruleForm.goodsLimitConfig.limitEndTime = this.dateRange[1];
      //       }

      //       this.ruleForm.goodsLimitConfig.isTimeLimit = this.checked1?'1':'0';
      //       this.ruleForm.goodsLimitConfig.isSingleBuyLimit = this.checked2?'1':'0';
      //       this.ruleForm.goodsLimitConfig.isWarzoneShelfLimit = this.checked3?'1':'0';
      //       if(this.checked2 && this.checked3){this.ruleForm.goodsLimitConfig.isBuyLimit='0'};
      //       console.log(this.ruleForm.goodsLimitConfig)

      //  if (this.ruleForm.goodsLimitConfig.isBuyLimit == '1') {
      //         if (this.ruleForm.goodsLimitConfig.isSingleBuyLimit == '0' && this.ruleForm.goodsLimitConfig.limitCount == "") {
      //         this.$message.error("限购时，用户购买数及不限量不能同时为空");
      //         return;
      //         }
      //         if (this.ruleForm.goodsLimitConfig.isWarzoneShelfLimit == '0' && this.ruleForm.goodsLimitConfig.shelfLimitCount == "") {
      //         this.$message.error("限购时，大区上架数量限制及不限量不能同时为空");
      //         return;
      //         }
      //         if (this.ruleForm.goodsStyle == 2 && !this.checked2 && this.ruleForm.goodsLimitConfig.limitCount < this.ruleForm.minBuyCount){
      //           this.$message.error("限购时，用户购买数不能低于最小购买数");
      //         return;
      //         }
      //         if (this.ruleForm.goodsStyle == 2 && !this.checked3 && this.ruleForm.goodsLimitConfig.shelfLimitCount < this.ruleForm.minBuyCount){
      //           this.$message.error("限购时，大区上架数量限制不能低于最小购买数");
      //         return;
      //         }
      //       }
      let pictures = [];
      this.fileList2.forEach((item, i) => {
        if (item != null) {
          let data = {
            picUrl: item.url,
            picId: item.picId,
            picType: 2,
          };
          pictures.push(data);
        }
      });
      let picture = '';
      this.fileList6.forEach((item, i) => {
        if (item != null) {
          picture = {
            picUrl: item.url,
            picId: item.picId,
            picType: 1,
          };
        }
      });

      let img = '';
      this.fileList3.forEach((item, i) => {
        img = {
          picUrl: item.url,
          picId: item.picId,
          picType: 3,
        };
      });

      // let values = [];
      // this.ruleForm.paramValueList.forEach((item, i) => {
      //   let data = {
      //     featuresValue: item.featuresValue
      //   };
      //   values.push(data);
      // });

      this.keepAlive = false;

      let data = {
        goodsId: this.ruleForm.goodsId,
        barCode: this.ruleForm.barCode,
        goodsName: this.ruleForm.goodsName,
        goodsStyle: this.ruleForm.goodsStyle,
        minBuyCount:
          this.ruleForm.goodsStyle == 2 ? this.ruleForm.minBuyCount : '',
        isOnly: this.ruleForm.goodsStyle == 2 ? this.ruleForm.isOnly : '',
        minUnitGoodsId:
          this.ruleForm.isMinUnit != '1' ? this.ruleForm.minUnitGoodsId : '',
        unitConvertRate:
          this.ruleForm.isMinUnit != '1' ? this.ruleForm.unitConvertRate : '',
        brandReq: this.ruleForm.brandReq,
        // sysCode: this.ruleForm.sysCode,
        goodsTypeId: this.ruleForm.goodsTypeId,
        status: this.ruleForm.status,
        unit: this.ruleForm.unit,
        sortNo: this.ruleForm.sortNo,
        isMinUnit: this.ruleForm.isMinUnit,
        minUniT: this.ruleForm.minUniT,
        // tagType: this.ruleForm.tagType.join(','),
        upLower: this.ruleForm.upLower,
        isGift: this.ruleForm.isGift,
        unit: this.ruleForm.unit,
        priceId: this.ruleForm.priceId,
        saleLowerPrice: Number(this.ruleForm.saleLowerPrice),
        activityPrice: Number(this.ruleForm.activityPrice),
        salePrice: Number(this.ruleForm.salePrice),
        memberPrice: this.ruleForm.goodsStyle == 1 || this.ruleForm.goodsStyle == 4 ? Number(this.ruleForm.memberPrice) : '',
        labellist: this.ruleForm.labellist,
        recommend: this.ruleForm.recommend,
        consumerIntegral: this.ruleForm.goodsStyle == 1 || this.ruleForm.goodsStyle == 4 ? this.ruleForm.consumerIntegral : '',
        merchantIntegral: this.ruleForm.goodsStyle == 1 || this.ruleForm.goodsStyle == 4 ? this.ruleForm.merchantIntegral : '',
        saleUpperPrice: Number(this.ruleForm.saleUpperPrice),
        goodsDescribe: this.ruleForm.goodsDescribe,
        pictures: pictures,
        picture: picture,
        img: img,
        // values: this.ruleForm.paramValueList, //values
        isComb: '1',
        //商品限购配置

        goodsLimitConfig: this.ruleForm.goodsLimitConfig,
        // {
        //   isBuyLimit: 1,//是否限购商品(1-是0-否)
        //   isTimeLimit: 1,//是否时效性商品(1-是0-否)
        //   limitCreateTime: '2020-06-18 00:00:00',//开始时间
        //   limitEndTime: '2020-06-18 01:00:00',//结束时间
        //   isSingleBuyLimit: 1,//每个用户购买是否限量(1-是0-否)
        //   limitCount: 2,//用户购买限制数
        //   isWarzoneShelfLimit: 1,//大区上架数量是否限量(1-是0-否)
        //   shelfLimitCount: 50//大区上架限制数
        // }
      };

      console.log('this.ruleForm', this.ruleForm)
      console.log('data', data)
      // return

      this.loading = true;
      if (this.editflag) {
        // 新增
        createGoodsInfo(data).then((res) => {
          this.$message({
            showClose: true,
            message: res.message,
            type: 'success',
          });
          this.resetForm();
        }).finally(() => {
          this.loading = false
        });
      } else {
        modifyGoodsInfo(data).then((res) => {
          this.$message({
            showClose: true,
            message: res.message,
            type: 'success',
          });
          this.resetForm();
        }).finally(() => {
          this.loading = false
        });
      }
      // } else {
      //     console.log("error submit!!");
      //     return false;
      // }
      // });
    },

    //取消
    resetForm() {
      this.$router.push('headProductmanage');
    },
    //分页
    handleSizeChange(val) {
      this.listQuery.size = val;
      this.search();
    },
    handleCurrentChange(val) {
      this.listQuery.current = val;
      this.search();
    },
    //新增特征组
    addFeatures() {
      this.dialogVisibleFeatures = !this.dialogVisibleFeatures;
      this.featuresForm.groupName = '';
    },
    //下拉特征组
    getGoodsGroupList() {
      let data = {};
      getGoodsGroupList(data).then((res) => {
        this.groupData = res.records;
      });
    },
    confirmEditone() {
      let data = {
        groupName: this.featuresForm.groupName,
      };
      addGoodsGroup(data).then((res) => {
        this.$message({
          showClose: true,
          message: res.message,
          type: 'success',
        });
        this.dialogVisibleFeatures = !this.dialogVisibleFeatures;
        this.getGoodsGroupList();
      });
    },
    //新增特征参数
    addFeaturesParam() {
      this.dialogVisibleFeaturesParam = !this.dialogVisibleFeaturesParam;
      this.featuresParamForm.parameterName = '';
      this.featuresParamForm.sortNo = '0';
      this.featuresParamList = [
        {
          groupId: '',
          parameterName: '',
          sortNo: this.ruleForm.paramValueList.length + 1,
          parameterId: '',
          valueId: '',
        },
      ];
      this.featuresParamData = [];
    },
    confirmFeaturesParam() {
      this.isDisable = true;
      setTimeout(() => {
        this.isDisable = false;
      }, 2000);
      if (this.ruleForm.groupId == '' || this.ruleForm.groupId == null) {
        this.$message.error('请选择特征组');
        return;
      }
      this.ss = this.featuresParamList;
      if (this.ss.length > 0) {
        this.ss.forEach((item, i) => {
          let data = {
            parameterName: item.parameterName,
            sortNo: item.sortNo,
            groupId: this.ruleForm.groupId,
          };
          this.featuresParamData.push(data);
        });
      }
      let data = this.featuresParamData;
      batchaRenewGoodsParam(data).then((res) => {
        this.$message({
          showClose: true,
          message: res.message,
          type: 'success',
        });
        this.dialogVisibleFeaturesParam = !this.dialogVisibleFeaturesParam;
        this.getGoodsGroupList();
        this.getGoodsParamsList2();
      });
    },
    addfeaturesParam() {
      this.featuresParamList.push({
        groupId: '',
        parameterName: '',
        sortNo:
          this.ruleForm.paramValueList.length +
          this.featuresParamList.length +
          1,
        parameterId: '',
        valueId: '',
      });
    },
    handlerRemove(item) {
      var index = this.featuresParamList.indexOf(item);
      if (index !== -1) {
        this.featuresParamList.splice(index, 1);
      }
    },
    getGoodsParamsList(v) {
      if (this.ruleForm.groupId == '' || this.ruleForm.groupId == null) {
        this.ruleForm.paramValueList = [];
        return;
      }
      let data = {
        groupId: this.ruleForm.groupId,
      };
      this.ruleForm.paramValueList = [];
      getGoodsParamsList(data).then((res) => {
        res.records.forEach((item, i) => {
          if (item != null) {
            this.ruleForm.paramValueList.push(item);
          }
        });
      });
    },
    getGoodsParamsList2() {
      // if (this.groupData !== undefined && this.groupData.length > 0) {
      //     this.ruleForm.groupId = this.groupData[0].groupId;
      //     this.getGoodsParamsList();
      // }
      let data = {
        groupId: this.ruleForm.groupId,
      };
      var array1 = [];
      var array2 = this.ruleForm.paramValueList;
      var array3 = this.featuresParamList;
      getGoodsParamsList(data).then((res) => {
        res.records.forEach((item, i) => {
          array1.push(item);
        });
        for (let i = 0; i < array1.length; i++) {
          let flag = true;
          for (let j = 0; j < array2.length; j++) {
            if (array1[i].parameterId == array2[j].parameterId) {
              flag = false;
            }
          }
          if (flag) {
            for (let k = 0; k < array3.length; k++) {
              if (array1[i].parameterName == array3[k].parameterName) {
                array2.push(array1[i]);
              }
            }
          }
        }
      });
    },
    onRadioChange(item) {
      console.log('item', item);
    },
    toPrice(val, type) {
      // 值，符号
      if (val === null || val === undefined || val === '') {
        return '0.00';
      } else {
        var data = Number(val)
          .toFixed(2)
          .split('.');
        var newData = data[0]
          .split('')
          .reverse()
          .join('');
        if (type) {
          return (
            type +
            newData
              .split('')
              .reverse()
              .join('')
              .slice(1) +
            '.' +
            data[1]
          );
        } else {
          return (
            newData
              .split('')
              .reverse()
              .join('')
              .slice(0) +
            '.' +
            data[1]
          );
        }
      }
    },
    toPrice2(val, type) {
      // 值，符号
      if (val === null || val === undefined || val === '') {
        return '1.00';
      } else {
        // if (Number(val) <= Number(this.ruleForm.saleLowerPrice)) {
        //   this.$message({
        //     showClose: true,
        //     message: "标准价不能低于底价",
        //     type: "info"
        //   });
        //   return Number(this.ruleForm.saleLowerPrice) + 1 + ".00";
        // }
        var data = Number(val)
          .toFixed(2)
          .split('.');
        var newData = data[0];
        if (type) {
          return type + newData.slice(1) + '.' + data[1];
        } else {
          return newData.slice(0) + '.' + data[1];
        }
      }
    },
    toPrice3(val, type) {
      // 值，符号
      if (val === null || val === undefined || val === '') {
        return '1.00';
      } else {
        if (Number(val) <= Number(this.ruleForm.salePrice)) {
          this.$message({
            showClose: true,
            message: '上限价不能低于标准价',
            type: 'info',
          });
          return Number(this.ruleForm.salePrice) + 1 + '.00';
        }
        var data = Number(val)
          .toFixed(2)
          .split('.');
        var newData = data[0];
        if (type) {
          return type + newData.slice(1) + '.' + data[1];
        } else {
          return newData.slice(0) + '.' + data[1];
        }
      }
    },
    //删除行数
    handleDelete(index) {
      this.ruleForm.paramValueList.splice(index, 1);
    },
    queryGoodsTypeList() {
      let data = {
        size: 99,
        current: 1,
        condition: {},
      };
      queryGoodsTypeList(data).then((res) => {
        this.tagTypeform.tagTypeCodes = [];
        res.records.forEach((item, i) => {
          let data = {
            id: item.uuid,
            label: item.tagName,
          };
          this.tagTypeform.tagTypeCodes.push(data);
          // this.tagTypeform.tagTypeCodes.push(item.tagName);
        });
      });
    },
    handleInput2(e) {
      // 通过正则过滤小数点后两位
      e.target.value = e.target.value.match(/^\d*(\.?\d{0,1})/g)[0] || null;
    },
    checkSortNo(val, type) {
      // 值，符号
      if (val === null || val === undefined || val === '') {
        return this.total + 1;
      } else {
        var aaa = Number(this.total + 1);
        if (Number(val) < aaa) {
          this.$confirm(
            '此操作将排序小于推荐值' + aaa + ', 是否继续?',
            '提示',
            {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning',
            }
          )
            .then(() => {
              return (this.ruleForm.sortNo = val);
            })
            .catch(() => {
              return (this.ruleForm.sortNo = aaa);
            });
        } else {
          return val;
        }
      }
    },
    ready(editorInstance) {
      console.log(`编辑器实例${editorInstance.key}: `, editorInstance);
    },
    handleExceed(file, fileList6) {
      this.$message.error(`图片最多上传1张`);
    },
    getInfoMax() {
      getInfoMax().then((res) => {
        if (res.code == 1) {
          this.ruleForm.sortNo = res.result.max + 1;
        }
      });
    },
    test() {
      console.log(this.ruleForm.tagType);
    },
    check(v) {
      let val = v;
      if (val === null || val === undefined || val === '') {
        this.$message({
          showClose: true,
          message: '填入数量不能为空',
          type: 'info',
        });
        val = 1;
      } else if (isNaN(val)) {
        this.$message({
          showClose: true,
          message: '填入数量格式错误',
          type: 'info',
        });
        val = 1;
      } else if (val < 1) {
        this.$message({
          showClose: true,
          message: '填入数量应大于0',
          type: 'info',
        });
        val = 1;
      }
      this.ruleForm.minBuyCount = parseInt(val);
      return true;
    },

    dayCountCheck(count) {
      let val = count;
      if (val === '') {
      } else if (isNaN(val)) {
        this.$message({
          showClose: true,
          message: '填入数量格式错误',
          type: 'info',
        });
      } else if (
        this.ruleForm.goodsStyle == 2 &&
        val < this.ruleForm.minBuyCount
      ) {
        this.$message({
          showClose: true,
          message: '宴席商品时填入数量应大于等于最小购买数',
          type: 'info',
        });
        this.ruleForm.goodsLimitConfig.limitCount = this.ruleForm.minBuyCount;
      }
      return true;
    },
    //删除图片
    deleImg(data, index) {
      this.fileList2.splice(index, 1);
    },
  },
  beforeRouteLeave(to, from, next) {
    // 设置下一个路由的 meta
    to.meta.keepAlive = this.keepAlive; // C 跳转到 A 时让 A 不缓存，即刷新
    next();
  },
};
</script>

<style lang="less" scoped>
.input_edit {
  // position: relative;
  font-size: 14px;
  //display: inline-block;
  width: 300px;
}

.label_edit {
  margin-left: 50px;
}

.title {
  display: block;
  margin-left: 2%;
  margin-bottom: 2%;
  font-size: 17px;
  color: #666 !important;
}

.adminSet {
  border: 1px solid #ebeef5;
  margin-left: 5px;
  padding: 31px 0px 20px 16px;
  width: 85%;
}

.el-item:hover .el-icon-error {
  visibility: inherit;
}

.el-items .el-icon-error {
  font-size: 22px;
  padding: 10px;
  color: red;
  cursor: pointer;
  visibility: hidden;
}

.float-button {
  position: absolute; //fixed; //关键
  height: 30px;
  width: 65px;
  top: 0px;
  // bottom: 90px;
  right: 15%;
  // background: #b4d145;
}

.tips {
  margin-left: 10px;
  color: red;
  font-size: 12px;
}

.divBox {
  /*flex-direction: row;*/
  float: left;
  position: relative;
}

.imgSty {
  margin: 10px;
}

.delIcon {
  position: absolute;
  top: 10px;
  right: 10px;
  font-size: 20px;
  color: red;
}

.form-item-inline {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  align-items: center;
}
</style>

<style>
.item .el-form-item__label {
  color: red;
}
</style>
